<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Application_Model_DbTable_manageuser extends Application_Model_DbTable_DomainObject{

    public function getMapper(){
		
   }
        
    public function GetBootAll($username,$email,$storeno,$starttime,$endtime,$dateselect,$pagesize,$pageindex){
        $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');  
	$db = $bootstrap->getResource('db');
	$where = '1=1';
	if ($username != '') {
		$where .= $db->quoteInto(" AND u.`username` LIKE ?", '%' . $this->_getParam('username') . '%');
	}
	if ($email != '') {
		$where .= $db->quoteInto(" AND u.`email` LIKE ?", '%' . $this->_getParam('email') . '%');
	}
	if ($storeno != '') {
		$where .= $db->quoteInto(" AND u.`storeno` LIKE ?", '%' . $this->_getParam('storeno') . '%');
	}
	if ($starttime != '') {
		if ($dateselect == 'regedit') {
		    $where .= $db->quoteInto(" AND u.`datecreated` >= ?", $this->_getParam('starttime'));
		} else {
		    $where .= $db->quoteInto(" AND u.`lastLogin` >= ?", $this->_getParam('starttime'));
		}
	}	
	if ($endtime != '') {
		if ($dateselect == 'regedit') {
		    $where .= $db->quoteInto(" AND u.`datecreated` <= ?", $this->_getParam('endtime'));
		} else {
		    $where .= $db->quoteInto(" AND u.`lastLogin` <= ?", $this->_getParam('endtime'));
		}
	}		
        $pageSize = $pagesize > 0 ? $pagesize : 15;
	$pageIndex = $pageindex > 0 ? $pageindex : 1;
	$offset = ($pageIndex - 1) * $pageSize;
                
	$count = $db->fetchOne("SELECT COUNT(*) FROM uuch_user u WHERE $where");
	$rows = $db->fetchAll("SELECT u.*,a.money,a.score,p.address FROM uuch_user u LEFT JOIN uuch_account a ON u.id = a.id LEFT JOIN uuch_profile p ON u.id = p.userId WHERE $where ORDER BY id DESC  LIMIT $offset, $pageSize");
	$result[0] = $count;
        $resulr[1] = $rows;
        return $resulr;
    }
}

?>
